{include file="header/index" /}

<!-- 加载动画 -->
<div class="spiner-example hides" style="position: fixed; top: 30px; left:50%; margin-left: -35px">
    <div class="sk-spinner sk-spinner-three-bounce">
        <div class="sk-bounce1"></div>
        <div class="sk-bounce2"></div>
        <div class="sk-bounce3"></div>
    </div>
</div>

<div class="container bgwhite">
    <h2 class="container-title ">修改工单</h2>

    <form class="form-horizontal" enctype="multipart/form-data" action="{:url('/admin/workorder/modify')}" method="post">
        <div class="mb40 woekorder">
            <h3 class="mt30 fs14 col-333">用户信息</h3>
            <div class="clearfix">
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">用户</label>
                    <input onclick="openModel(1)" class="no-input" type="text" value="{$userData[0]['username']}" name="_username" readonly="readonly" placeholder="点击选择"  />
                    <i class="col-red">*</i>
                </p>
                <!--隐藏域，用来装工单ID-->
                <input type="hidden" name="work_order_id" value="{$workData['work_order_id']}" />
                <!--隐藏域，用来装选中用户的id-->
                <input type="hidden" id="user_id" name="user_id" value="{$userData[0]['user_id']}" />
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">用户电话</label>
                    <input type="text" value="{$userData[0]['telphone']}" name="telphone" readonly="readonly" />
                    <i class="col-red">*</i>
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">合同编号</label>
                    <input onclick="openModels(1)" class="no-input" type="text" value="{$contractData[0]['contract_no'] ? $contractData[0]['contract_no'] : ''}" name="contract_no" readonly="readonly" placeholder="点击选择" />
                    <i class="col-red">*</i>
                </p>
                <!--隐藏域，用来装选中合同的id-->
                <input type="hidden" id="contract_id" name="contract_id" value="{$contractData[0]['contract_id'] ? $contractData[0]['contract_id'] : ''}" />
                <!--合同标识符-->
                <input type="hidden" name="identifier" value="{$identifier}" />
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">装机时间</label>
                    <input type="text" value="{$contractData[0]['installed_time'] ? $contractData[0]['installed_time'] : ''}" name="installed_time" id="installedTime" readonly="readonly" />
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">身份证号</label>
                    <input type="text" value="{$userData[0]['id_card']}" name="id_card" readonly="readonly" />
                    <i class="col-red">*</i>
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">续费周期</label>
                    <input class="col-red" type="text" value="{$contractData[0]['renew_date'] ? $contractData[0]['renew_date'] : ''}" name="renew_date" id="renewalTime" readonly="readonly" />
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">联系人</label>
                    <input type="text" value="{$workData['contacts']}" name="contacts" id="contacts_" />
                    <i class="col-red">*</i>
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">到期时间</label>
                    <input class="col-red" type="text" value="{$contractData[0]['exire_date'] ? $contractData[0]['exire_date'] : ''}" name="exire_date" id="exire_date_" readonly="readonly" />
                </p>
                <p class="mt20 mb20 fl">
                    <label class="addEnginerr-title">联系电话</label>
                    <input type="text" value="{$workData['contact_number']}" id="contact_number_" name="contact_number" />
                    <i class="col-red">*</i>
                </p>
            </div>

        </div>
        <div>
            <h3 class="mt30 fs14 col-333">基本信息</h3>

            <p class="mt20 mb20">
                <label class="addEnginerr-title">业务类型</label>
                <select class="workOrder-select" name="businessid" onchange="ShiftSelect(this)" id="business_id">

                    <option value="0">请选择</option>
                    {foreach $workType as $k=>$v}
                    <option value="{$k}" {if condition="(isset($workData['business_id']) AND $k == $workData['business_id'])"}selected{/if}>{$v}</option>
                    {/foreach}

                </select>
                <i class="col-red">*</i>
            </p>

            <!--当前工单状态-->
            <input type="hidden" value="{$business}" name="_business" />
            <!--页面标识数-->
            <input type="hidden" value="{$who}" name="who" />
            <!--默认为隐藏，选着移机会弹出-->
            <div class="ShiftCenter hides">
                <p class="mt20 mb20 clearfix">
                    <label class="addEnginerr-title"></label>
                    <span class="mr20 fl"><input class="fl" type="radio" name="shift" value="5" {if condition="(isset($business) AND $business == 5)"}checked="checked"{/if}>移机</span>
                    <span class="mr20 fl"><input class="fl" type="radio" name="shift" value="9" {if condition="(isset($business) AND $business == 9)"}checked="checked"{/if}>移机拆</span>
                    <span class="mr20 fl"><input class="fl" type="radio" name="shift" value="10" {if condition="(isset($business) AND $business == 10)"}checked="checked"{/if}>移机装</span>
                </p>

                <!--是否同一用户-->
                <input type="hidden" value="{$workData['isuser']}" id="is_user" />
                <p class="mt20 mb20 clearfix">
                    <label class="addEnginerr-title">是否是同一用户</label>
                    <select class="workOrder-select" name="isuser" id="isuser" onchange="test()">
                        <option value="0">请选择</option>
                        <option value="1" {if condition="(isset($workData['isuser']) AND $workData['isuser'] == 1)"}selected{/if}>是</option>
                        <option value="2" {if condition="(isset($workData['isuser']) AND $workData['isuser'] == 2)"}selected{/if}>否</option>
                    </select>
                    <i class="col-red">*</i>
                </p>

                <p class="mt20 mb20">
                    <input type="hidden" name="moveprovince" value="{$workData['move_province']}" />
                    <input type="hidden" name="movecity" value="{$workData['move_city']}" />
                    <input type="hidden" name="movearea" value="{$workData['move_area']}" />
                    <label class="addEnginerr-title">移机区域</label>
                    <select class="addEnginerr-select" id="province" name="province_id" onchange="province__()">
                        <option value="">--请选择省--</option>
                        {volist name="province" id="p"}
                        <option value="{$p.id}" data="{$p.id}" {if condition="($p.id == $workData['move_province_code'])"}selected{/if}>{$p.area_name}</option>
                        {/volist}
                    </select>
                    <select class="addEnginerr-select" id="city" name="city_id" onchange="city__()">
                        <option value="">--请选择市--</option>
                        {volist name="city" id="c"}
                        <option value="{$c.id}" data="{$c.id}" {if condition="($c.id == $workData['move_city_code'])"}selected{/if}>{$c.area_name}</option>
                        {/volist}
                    </select>
                    <select class="addEnginerr-select" id="area" name="area_id" onchange="area__()">
                        <option value="">--请选择区/县--</option>
                        {volist name="area" id="a"}
                        <option value="{$a.id}" data="{$a.id}" {if condition="($a.id == $workData['move_area_code'])"}selected{/if}>{$a.area_name}</option>
                        {/volist}
                    </select>
                    <i class="col-red">*</i>
                </p>

                <p class="mt20 mb20">
                    <label class="addEnginerr-title">详细地址</label>
                    <input id="addressDetails" class="addEnginerr-input" type="text" value="{$workData['move_address']}" name="service_address" placeholder="请输入详细地址"  />
                    <i class="col-red">*</i>
                </p>

            </div>

            <div class="ShiftCenters">
                <p class="mt20 mb20">
                    <label class="addEnginerr-title">装机设备+设备编号</label>
                    <select class="workOrder-select" id="equipments_name" name="equipmentsname">
                        {volist name="$equipmentsNumber" id="k"}
                        <option value="{$k.id}" {if condition="($equipments_number == $k.equipments_number AND $equipments_name == $k.equipments_name)"}selected{/if}>{$k.equipments_name}--{$k.equipments_number}</option>
                        {/volist}
                    </select>
                    <i class="col-red">*</i>
                </p>

            </div>


            <!--默认为显示，选着移机时是同一用户会隐藏-->
            <div class="ShiftCenterss">
                <p class="mt20 mb20 relative">
                    <label class="addEnginerr-title">费用</label>
                    <input class="workOrder-input" type="text" value="{$workData['combo_money']}" name="combo_money" id="combo_money" placeholder="￥0.00" maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'')" />
                    <span class="fs12 col-333 absolute" style="left: 235px;top: 5px;">元</span>
                    <i class="col-red">*</i>
                </p>

                <p class="mt20 mb20">
                    <input type="hidden" name="userprovince" value="{$workData['province']}" />
                    <input type="hidden" name="usercity" value="{$workData['city']}" />
                    <input type="hidden" name="userarea" value="{$workData['area']}" />
                    <label class="addEnginerr-title">用户地址</label>
                    <select class="addEnginerr-select" id="_province" name="province_code" onchange="province_()">
                        <option value="">--选择省--</option>
                        {volist name="province" id="p"}
                        <option value="{$p.id}" data="{$p.id}" {if condition="($p.id == $workData['province_code'])"}selected{/if}>{$p.area_name}</option>
                        {/volist}
                    </select>
                    <select class="addEnginerr-select" id="_city" name="city_code" onchange="city_()">
                        <option value="">--选择市--</option>
                        {volist name="city" id="c"}
                        <option value="{$c.id}" data="{$c.id}" {if condition="($c.id == $workData['city_code'])"}selected{/if}>{$c.area_name}</option>
                        {/volist}
                    </select>
                    <select class="addEnginerr-select" id="_area" name="area_code" onchange="area_()">
                        <option value="">--选择区/县--</option>
                        {volist name="area" id="a"}
                        <option value="{$a.id}" data="{$a.id}" {if condition="$a.id eq $workData['area_code']"}selected{/if}>{$a.area_name}</option>
                        {/volist}
                    </select>
                    <i class="col-red">*</i>
                </p>
                <p class="mt20 mb20">
                    <label class="addEnginerr-title">详细地址</label>
                    <input id="addressDetail" class="addEnginerr-input" type="text" value="{$workData['service_address']}" name="user_address" placeholder="请输入详细地址" />
                    <i class="col-red">*</i>
                </p>
            </div>
            <p class="mt20 mb20 relative">
                <label class="addEnginerr-title">备注</label>
                <textarea class="addEnginerr-textarea" maxlength="500" name="remarks">{$workData['remarks']}</textarea>
                <span class="absolute txtNum_tis">500字以内</span>
            </p>
        </div>
        <p class="engineer-Btn">
            <input type="submit" id="submit" class="engineer-PreBtn" value="保存" />
            <a href="javascript:(0)" class="engineer-ResetBtn" onclick="reset()">重置</a>
            <a href="javascript:(0)" class="engineer-RuterBtn" onclick="window.history.go(-1);">返回</a>
        </p>
    </form>
</div>


<script>


    // 判断数据是否有值
    $("#submit").click(function(){
        if ($("#business_id").val() == 5) {
            if ($("#isuser").val() == 2) {
                if ($("#combo_money").val() == '') {
                    layer.msg('费用不能空', {icon: 0});
                    return false;
                }
                if ($("#_province").val() == '') {
                    layer.msg('请选择用户地址', {icon: 0});
                    return false;
                }
                if ($("input[name='user_address']").val() == '') {
                    layer.msg('详细地址不能为空', {icon: 0});
                    return false;
                }
            }
            if ($("input[name='_username']").val() == '') {
                layer.msg('用户不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='telphone']").val() == '') {
                layer.msg('用户电话不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='id_card']").val() == '') {
                layer.msg('身份证不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='contacts']").val() == '') {
                layer.msg('联系人不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='contact_number']").val() == '') {
                layer.msg('联系电话不能为空', {icon: 0});
                return false;
            }
            if ($("#business_id").val() == 0) {
                layer.msg('请选择业务类型', {icon: 0});
                return false;
            }
            if ($("input[name='contract_no']").val() == '') {
                layer.msg('合同信息不能为空', {icon: 0});
                return false;
            }

            if ($("#equipments_name").val() == '') {
                layer.msg('装机设备+设备编号不能为空', {icon: 0});
                return false;
            }

        }else{

            if ($("input[name='_username']").val() == '') {
                layer.msg('用户不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='telphone']").val() == '') {
                layer.msg('用户电话不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='id_card']").val() == '') {
                layer.msg('身份证不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='contacts']").val() == '') {
                layer.msg('联系人不能为空', {icon: 0});
                return false;
            }
            if ($("input[name='contact_number']").val() == '') {
                layer.msg('联系电话不能为空', {icon: 0});
                return false;
            }
            if ($("#business_id").val() == 0) {
                layer.msg('请选择业务类型', {icon: 0});
                return false;
            }
            if ($("#business_id").val() != 3) {
                if ($("input[name='contract_no']").val() == '') {
                    layer.msg('合同信息不能为空', {icon: 0});
                    return false;
                }
            }
            if ($("#business_id").val() != 3) {
                if ($("#equipments_name").val() == '') {
                    layer.msg('装机设备+设备编号不能为空', {icon: 0});
                    return false;
                }
            }
            if ($("#combo_money").val() == '') {
                layer.msg('费用不能空', {icon: 0});
                return false;
            }
            if ($("#_province").val() == '') {
                layer.msg('请选择用户地址', {icon: 0});
                return false;
            }
            if ($("input[name='user_address']").val() == '') {
                layer.msg('详细地址不能为空', {icon: 0});
                return false;
            }
        }
    });


    // 页面初始化的时候判断是否新装工单
    $(function(){
        var business = $("input[name='_business']").val();
        if (business == 3) {
            $(".ShiftCenters").hide();
        }
    });


    // 页面初始化的时候判断是否同一用户
    $(function(){
        var isuser = $('#isuser').val();
        if(isuser == 1){
            $(".ShiftCenterss").hide();
        }
        if (isuser == 2) {
            $(".ShiftCenterss").show();
        }
    });

    // 页面初始化的时候判断是否是移机状态
    $(function(){
        var business =  $("input[name='_business']").val();
        if (business == 5 || business == 9 || business == 10) {
            $(".ShiftCenter").show();
            $(".ShiftCenters").show();
        }
    });



    // 判断联系电话不能为空
    $("#contact_number_").blur(function(){
        var contact_number = $("#contact_number_").val();
        if (contact_number == '') {
            layer.msg('联系电话不能为空', {icon: 0});
            return false;
        }
    });
    // 判断联系人不能为空
    $("#contacts_").blur(function(){
        var contacts = $("#contacts_").val();
        if (contacts == '') {
            layer.msg('联系人不能为空', {icon: 0});
            return false;
        }
    });
    // 判断服务详细地址不能为空
    $("#addressDetail").blur(function(){
        var addressDetail = $("#addressDetail").val();
        if (addressDetail == '') {
            layer.msg('详细地址不能为空', {icon: 0});
            return false;
        }
    });
    // 判断费用不能为空
    $("#combo_money").blur(function(){
        var combo_money = $("#combo_money").val();
        if (combo_money == '') {
            layer.msg('费用不能空', {icon: 0});
            return false;
        }
    });

    // 选择合同弹窗页面
    function openModels(type) {
        // 获取选择用户id
        var userid = $("#user_id").val();
        if (userid == '') {
            layer.msg('请先选择用户', {icon: 0});
            return false;
        }
        var html = '';
        html +='<div id="userh">';
        html +='<div class="modal-body">';
        html +='<h2 class="fs14 col-666 mb10">选择合同</h2>';
        html +='<p>';
        html +='<input class="modalUser-input" type="text" name="contractno" placeholder="请输入合同编号">';
        html +='<button class="btn btn-primary mr10 pl15 pr15 pt3 pb3" onclick="search_()">搜索</button>';
        html +='</p>';
        html +='<table class="table table-bordered mt20">';
        html +='<thead>';
        html +='<tr>';
        html +='<th></th>';
        html +='<th>合同编号</th>';
        html +='<th>签约合同</th>';
        html +='<th>续费周期</th>';
        html +='<th>到期时间</th>';
        html +='<th>设备台数</th>';
        html +='<th>合同金额</th>';
        html +='<th>合同状态</th>';
        html +='</tr>';
        html +='</thead>';
        html +='<tbody id="clist">';
        html +='<tr>';
//        html +='<td><input type="checkbox" name="" value=""></td>';
        html +='<td><input type="radio" name="contractNo" value=""></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='</tr>';
        html +='</tbody>';
        html +='</table>';

        html +='<div class="">';
        html +='<div class=" clearfix">';
        html +='<div class="clearfix" style="float:right;margin: 0 auto;">';
        html +='<span class="fl mt5" id="count">共0条数据</span><span id="allpage"  class="fl  mr20 mt5"></span><span  class="fl" id="AjaxPage"></span>';
        html +='</div>';
        html +='<div class="spiner-example">';
        html +='<div class="sk-spinner sk-spinner-three-bounce">';
        html +='<div class="sk-bounce1"></div>';
        html +='<div class="sk-bounce2"></div>';
        html +='<div class="sk-bounce3"></div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';
        html +='<div class="modal-footer t_center">';
        html +='<button type="button" onclick="contractqr()" class="btn btn-primary ml30 mr30 pl20 pr20 pt3 pb3">确认</button>';
        html +='<button type="button" class="btn btn-default ml30 mr30 pl20 pr20 pt3 pb3" onclick="cancelmodel()">取消</button>';
        html +='</div>';
        html +='</div>';
        //页面层
        parent.layer.open({
            title:'选择合同',
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['823px', '490px'], //宽高
            content: html
        });
        Ajaxpages(1);
    }
    // 处理选择合同弹窗页面分页
    function Ajaxpages(curr) {
        // 合同编号 搜索
        var contract_no = $.trim(parent.$("input[name='contractno']").val());
        // 获取选择用户id
        var userid = $("#user_id").val();
        $.getJSON('{:url("/administrative/workorder/getcontract")}', {
            page: curr || 1,
            userid: userid,
            contract_no: contract_no
        }, function(data) {
            parent.$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
            if(data == '') {
                parent.$("#clist").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
                parent.$('#count').html("共" + 0 + "条数据");
            } else {
                // 字符串拼接
                $("#clist").html('');
                var str = '';
                $.each(data,function(k,v){
                    str +='<tr>';
//                    str +='<td><input type="checkbox" name="" value="'+v.contract_no+'" contract_id="'+v.contract_id+'" renew_date="'+v.renew_date+'" installed_time="'+v.installed_time+'" exire_date="'+v.exire_date+'"></td>';
                    str +='<td><input type="radio" name="contractNo" value="'+v.contract_no+'" contract_id="'+v.contract_id+'" renew_date="'+v.renew_date+'" installed_time="'+v.installed_time+'" exire_date="'+v.exire_date+'"></td>';
                    str +='<td>' + v.contract_no + '</td>';
                    str +='<td>' + v.installed_time + '</td>';
                    str +='<td>' + v.renew_date + '</td>';
                    str +='<td>' + v.exire_date + '</td>';
                    str +='<td>' + v.equipmentCount + '</td>';
                    str +='<td>' + v.contract_money + '元</td>';
                    str +='<td>' + v.contract_status + '</td>';
                    str +='</tr>';
                });
                parent.$("#clist").html(str);

                // 总的数据
                parent.$('#count').html("共" + data[0].count + "条数据");
                parent.laypage({
                    cont: parent.$('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                    pages: data[0].allPage, //总页数
                    skip: true, //是否开启跳页
                    skin: '#337ab7', //分页组件颜色
                    curr: curr || 1,
                    first: '首页', //若不显示，设置false即可
                    last: '尾页', //若不显示，设置false即可
                    groups: 3, //连续显示分页数
                    jump: function(obj, first) {
                        if(!first) {
                            Ajaxpages(obj.curr)
                        }
                        parent.$('#allpage').html(',第' + obj.curr + '页，共' + obj.pages + '页');
                    }
                });
            }
        });
    }
    // 选中合同后执行，获取设备信息
    function equipmentssss(contract_id){
        if ($("#business_id option:selected").val() != 3) {
            if ($("#equipments_name").val() == null) {
                // 发送ajax请求，获取装机设备跟设备编号
                $.getJSON("{:url('/administrative/workorder/getequipments')}", {contract_id: contract_id}, function (data) {
                    $("#equipments_name").html('');
                    var str = '';
                    $.each(data, function (k, v) {
                        str += '<option value="' + v.id + '">' + v.equipments_name + '---' + v.equipments_number + '</option>';
                    });
                    $("#equipments_name").html(str);
                });
            }
        }
    }


    // 选择用户弹窗页面
    function openModel(type) {
        var html = '';
        html +='<div id="userh">';
        html +='<div class="modal-body">';
        html +='<h2 class="fs14 col-666 mb10">选择用户</h2>';
        html +='<p>';
        html +='<input class="modalUser-input" type="text" name="username" placeholder="请输入用户">';
        html +='<input class="modalUser-input" type="text" name="telphone__" placeholder="请输入联系电话">';
        html +='<input class="modalUser-input" type="text" name="id_card__" placeholder="请输入身份证号码">';
        html +='<button onclick="search()" class="btn btn-primary mr10 pl15 pr15 pt3 pb3">搜索</button>';
        html +='<button class="btn btn-primary pl15 pr15 pt3 pb3"><i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;<a href="/administrative/customerinfo/add">新增用户</a></button>';
        html +='</p>';
        html +='<table class="table table-bordered mt20">';
        html +='<thead>';
        html +='<tr>';
        html +='<th></th>';
        html +='<th>账号</th>';
        html +='<th>户名</th>';
        html +='<th>联系人电话</th>';
        html +='<th>身份证号</th>';
        html +='<th>账号状态</th>';
        html +='</tr>';
        html +='</thead>';

        html +='<tbody id="list">';
        html +='<tr>';
//        html +='<td><input type="checkbox" name="" value=""></td>';
        html +='<td><input type="radio" name="userName" value="" ></td>';
        html +='<td>dfgdfgdfgdfgd</td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='<td></td>';
        html +='</tr>';
        html +='</tbody>';

        html +='</table>';
        html +='<div class="">';
        html +='<div class=" clearfix">';
        html +='<div class="clearfix" style="float:right;margin: 0 auto;">';
        html +='<span class="fl mt5" id="count">共0条数据</span><span id="allpage"  class="fl  mr20 mt5"></span><span  class="fl" id="AjaxPage"></span>';
        html +='</div>';
        html +='<div class="spiner-example">';
        html +='<div class="sk-spinner sk-spinner-three-bounce">';
        html +='<div class="sk-bounce1"></div>';
        html +='<div class="sk-bounce2"></div>';
        html +='<div class="sk-bounce3"></div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';
        html +='</div>';

        html +='<div class="modal-footer t_center">';
        html +='<button type="button" onclick="qwer()" class="btn btn-primary ml30 mr30 pl20 pr20 pt3 pb3">确认</button>';
        html +='<button type="button" class="btn btn-default ml30 mr30 pl20 pr20 pt3 pb3" onclick="cancelmodel()">取消</button>';
        html +='</div>';
        html +='</div>';
        //页面层
        parent.layer.open({
            title:'选择客户',
            type: 1,
            skin: 'layui-layer-rim', //加上边框
            area: ['823px', '490px'], //宽高
            content: html
        });
        Ajaxpage(1);
    }
    // 处理选择用户弹窗页面分页
    function Ajaxpage(curr) {
        // 搜索数据
        var username = $.trim(parent.$("input[name='username']").val());  // 用户姓名
        var telphone = $.trim(parent.$("input[name='telphone__']").val()); // 联系电话
        var id_card = $.trim(parent.$("input[name='id_card__']").val());   // 身份证号
        $.getJSON('{:url("Workorder/getuser")}', {
            page: curr || 1,
            username: username,
            telphone: telphone,
            id_card: id_card
        }, function(data) {
            console.info(data);
            parent.$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
            if(data == '') {
                parent.$("#list").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
                parent.$('#count').html("共" + 0 + "条数据");
            } else {
                // 字符串拼接
                $("#list").html('');
                var str = '';
                $.each(data,function(k,v){
                    str +='<tr>';
//                    str +='<td><input type="checkbox" name="" value="'+v.username+'" data="'+v.user_id+'" id_card="'+v.id_card+'" telphone="'+v.telphone+'"></td>';
                    str +='<td><input type="radio" name="userName" value="'+v.username+'" data="'+v.user_id+'" id_card="'+v.id_card+'" telphone="'+v.telphone+'"></td>';
                    str +='<td>' + v.telphone + '</td>';
                    str +='<td>' + v.username + '</td>';
                    str +='<td>' + v.telphone + '</td>';
                    str +='<td>' + v.id_card + '</td>';
                    str +='<td>' + v.account_status + '</td>';
                    str +='</tr>';
                });
                // 将拼接的数据输出在页面
                parent.$("#list").html(str);
                // 总的数据
                parent.$('#count').html("共" + data[0].count + "条数据");
                parent.laypage({
                    cont: parent.$('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                    pages: data[0].allPage, //总页数
                    skip: true, //是否开启跳页
                    skin: '#337ab7', //分页组件颜色
                    curr: curr || 1,
                    first: '首页', //若不显示，设置false即可
                    last: '尾页', //若不显示，设置false即可
                    groups: 3, //连续显示分页数
                    jump: function(obj, first) {
                        if(!first) {
                            Ajaxpage(obj.curr)
                        }
                        parent.$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
						inputlength();
                    }
                });
            }
        });
    }


    //重置
    function reset() {
        top.layer.confirm('你确定要重置吗?', {
            btn: ['确定', '取消'] //按钮
        }, function() {
            $(".form-horizontal")[0].reset();
            top.layer.msg('重置成功', {icon: 1});
        });
    }

    // 用户地址
    // 根据选中的省获取下面所有市
    function province_(){
        $("input[name='usercity']").val('');
        $("input[name='userarea']").val('');
        var province = $("#_province option:selected").html();
        $("input[name='userprovince']").val(province);
        var parent_id = $("#_province option:selected").attr('data');
        var str = '<option value="">--选择市--</option>';
        var str1 = '<option value="">--选择区/县--</option>';
        $("#_city").html(str);
        $("#_area").html(str1);
        // 发送ajax请求
        $.getJSON("{:url('/admin/Three/city')}",{parent_id:parent_id},function(data){
            var str = '<option value="">--选择市--</option>';
            $("#_city").html('');
            $.each(data,function(k,v){
                str += '<option value="' + v.area_name + '" data="'+ v.id +'">' + v.area_name + '</option>';
            });
            $("#_city").html(str);
        });
    }
    // 根据选中的市获取下面的区县
    function city_(){
        $("input[name='userarea']").val('');
        var city = $("#_city option:selected").html();
        $("input[name='usercity']").val(city);
        var city_id = $("#_city option:selected").attr('data');
        // 发送ajax请求
        $.getJSON("{:url('/admin/Three/areas')}",{city_id:city_id},function (data) {
            var str = '<option value="">--选择区/县--</option>';
            $("#_area").html('');
            $.each(data,function(k,v){
                str += '<option value="' + v.area_name + '">' + v.area_name + '</option>';
            });
            $("#_area").html(str);
        });
    }
    // 当区县改变时
    function area_(){
        var area = $("#_area option:selected").html();
        $("input[name='userarea']").val(area);
    }



    // 根据选中的省获取下面所有市
    function province__(){
        $("input[name='movecity']").val('');
        $("input[name='movearea']").val('');
        var province = $("#province option:selected").html();
        $("input[name='moveprovince']").val(province);
        var parent_id = $("#province option:selected").attr('data');
//        var str = '<option value="">--选择市--</option>';
//        var str1 = '<option value="">--选择区/县--</option>';
//        $("#_city").html(str);
//        $("#_area").html(str1);
        // 发送ajax请求
        $.getJSON("{:url('/admin/Three/city')}",{parent_id:parent_id},function(data){
            var str = '<option value="">--选择市--</option>';
            $("#city").html('');
            $.each(data,function(k,v){
                str += '<option value="' + v.area_name + '" data="'+ v.id +'">' + v.area_name + '</option>';
            });
            $("#city").html(str);
        });
    }
    // 根据选中的市获取下面的区县
    function city__(){
        $("input[name='movearea']").val('');
        var city = $("#city option:selected").html();
        $("input[name='movecity']").val(city);
        var city_id = $("#city option:selected").attr('data');
        // 发送ajax请求
        $.getJSON("{:url('/admin/Three/areas')}",{city_id:city_id},function (data) {
            var str = '<option value="">--选择区/县--</option>';
            $("#area").html('');
            $.each(data,function(k,v){
                str += '<option value="' + v.area_name + '">' + v.area_name + '</option>';
            });
            $("#area").html(str);
        });
    }
    // 当区县改变时
    function area__(){
        var area = $("#area option:selected").html();
        $("input[name='movearea']").val(area);
    }


    //当业务类型为移机时
    function ShiftSelect(obj){
        // 当业务类型切换时，清空是否同一用户
        $("#isuser").html('');
        // 当业务类型切换时，设备编号清空
//        $("#equipments_number").html('');
        var txt = $(obj).val();
        if (txt == 0) {
            layer.msg('请选择业务类型', {icon: 0});
            return false;
        }
        // 获取合同id
        var contract_id = $("#contract_id").val();

        // 先判断合同是否为空
//        if (contract_id == '') {
            // 合同编号为空的时候隐藏
//            $(".ShiftCenters").hide();
//        }else{
            // 当业务类型不为新装跟移机时
            if(txt != 3 && txt !=5 && txt !=0){
                // 发送ajax请求，获取装机设备跟设备编号
                $.getJSON("{:url('/administrative/workorder/getequipments')}",{contract_id:contract_id},function(data){
                    $("#equipments_name").html('');
                    var str = '';
                    $.each(data,function(k,v){
                        str += '<option value="' + v.id + '">' + v.equipments_name + '---'+ v.equipments_number +'</option>';
                    });
                    $("#equipments_name").html(str);
                });

                $(".ShiftCenterss").show();
                $(".ShiftCenters").show();
            }else{
                $(".ShiftCenters").hide();
                $(".ShiftCenterss").show();
            }
//        }

        // 先判断合同是否为空
        if (contract_id == '') {
            // 为空的时候隐藏
            $(".ShiftCenter").hide();
        }else{
            // 业务类型为移机的时候
            if(txt == 5){
                var is_user = $("#is_user").val();
                $("#isuser").html('');
                var str = '';
                if (is_user == 1) {
                    str += '<option value=1>是</option>';
                    str += '<option value=2>否</option>';
                    $(".ShiftCenterss").hide();
                }
                if (is_user == 2) {
                    str += '<option value=2>否</option>';
                    str += '<option value=1>是</option>';
                }
                if (is_user == '') {
                    str += '<option value=1>是</option>';
                    str += '<option value=2>否</option>';
                    $(".ShiftCenterss").hide();
                }
                $("#isuser").html(str);

                $(".ShiftCenter").show();
                $(".ShiftCenters").show();
            }else{
                $(".ShiftCenter").hide();
            }
        }
    }

    // 移机时，判断是否同一用户
    function test() {
        var isuser = $("#isuser option:selected").val();
        if(isuser == 1){
            $(".ShiftCenterss").hide();
        }
        if (isuser == 2) {
            $(".ShiftCenterss").show();
        }
    }


</script>
</body>

</html>